const fs = require("fs");
const path = require("path");
const csv = require("fast-csv");
const _ = require("lodash");
const convertintent = require("./convert.js");
const csvarray = [];
process.env.GOOGLE_APPLICATION_CREDENTIALS =
  "./GrantDialogflowNode-02f1c9fcdbb6.json";

fs.createReadStream(path.join(__dirname, "./csvintent.csv"))
  .pipe(csv.parse({ headers: true, ignoreEmpty: true, trim: true }))
  .on("error", error => console.error(error))
  .on("data", row => {
    csvarray.push(row);
  })
  .on("end", rowCount => {
    _.forEach(csvarray, item => {
      let a = [];
      let b = [];
      a.push(item.Question);
      b.push(item.Answer);
      convertintent(a, b, "PS_" + item.Question);
    });
  });
